package org.javaweb.cms_web.controller;

import org.javaweb.cms_web.model.FeedbackDTO;
import org.javaweb.cms_web.mapper.FeedbackDTOMapper;

import org.javaweb.cms_web.model.User;
import org.javaweb.cms_web.util.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

//显示问题列表
@Controller
public class ViewFeedbackController {

    @Autowired
    private FeedbackDTOMapper feedbackDTOMapper;
    @Resource
    private HostHolder hostHolder;

    @GetMapping("/ViewFeedbackController")
    public String viewFeedbacks(HttpSession session, Model model) {

        // 从 session 中获取用户 ID
        User user = hostHolder.getUser();
        if (user == null) {
            return "redirect:/login";
        }
        // 查询当前用户的反馈列表
        List<FeedbackDTO> feedbackDTOList = feedbackDTOMapper.getFeedbacksByUserId(user.getUserId());
//        System.out.println("feedbackList: " + feedbackList);

        // 将反馈列表添加到模型
        model.addAttribute("feedbackDTOList", feedbackDTOList);
        return "viewFeedbacks";
    }
}

